package com.yxp423.ssmempl.controller;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yxp423.ssmempl.bean.Process;
import com.yxp423.ssmempl.bean.Project;
import com.yxp423.ssmempl.bean.User;
import com.yxp423.ssmempl.bean.UserProject;
import com.yxp423.ssmempl.dto.ProcessDto;
import com.yxp423.ssmempl.service.IProcessService;
import com.yxp423.ssmempl.service.IProjectService;
import com.yxp423.ssmempl.utils.base.AjaxResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Description: java类作用描述
 * @Author: yxp
 * @CreateDate: 2019-05-11 16:17
 * @Version: 1.0
 */
@Controller
@RequestMapping("/project")
public class ProjectController {


	@Autowired
	IProjectService projectService;
	@Autowired
	IProcessService processService;

	/**
	 * 返回添加项目页面
	 *
	 * @return
	 */
	@GetMapping("/addproject")
	public String toProjectPage() {

		return "project/add_project";
	}
	@GetMapping("/toReviewProject")
	public String toReviewProject(){
		return "project/review_project";
	}

	@GetMapping("/updateproject")
	public String toUpdateProject(){

		return "project/update_project";
	}

	@GetMapping("/applyproject")
	@ResponseBody
	public AjaxResult applyProject(Project project) {
		AjaxResult result = new AjaxResult();

		result = projectService.saveProjectApply(project);

		return result;
	}




	@GetMapping("/getCheckingProject")
	@ResponseBody
	public AjaxResult getCheckingProject(Page page){
		AjaxResult result  = projectService.getCheckingProject(page);
		return result;
	}



	@GetMapping("/reviewProject")
	@ResponseBody
	public AjaxResult reviewProject(Project project){

		AjaxResult result = projectService.saveProjectReview(project);

		return result;

	}

	@GetMapping("/getMyApplyProject")
	@ResponseBody
	public AjaxResult saveProject(Page page){

		AjaxResult result = projectService.updateProject(page);

		return result;

	}


	@GetMapping("/updateSubmit")
	@ResponseBody
	public AjaxResult updateSubmit(ProcessDto processDto){

		AjaxResult result = new AjaxResult();


		result = projectService.updateSubmit(processDto);


		return result;
	}

	@GetMapping("/getpercentage")
	@ResponseBody
	public AjaxResult getPercentage(Process process){

		AjaxResult result  = new AjaxResult();

		result = processService.selectProcess(process);


		return  result;
	}


	@GetMapping("/getmyproject")
	@ResponseBody
	@ApiOperation("获得我所在的所有项目")
	public AjaxResult getMyProject(UserProject userProject){
//		AjaxResult result = new AjaxResult();

		return projectService.getMyProject(userProject);
	}


}
